package com.ruoyi.bluebera.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bluebera.domain.BizExchangeRates;
import com.ruoyi.bluebera.service.IBizExchangeRatesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汇率记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/bluebera/rates")
public class BizExchangeRatesController extends BaseController
{
    @Autowired
    private IBizExchangeRatesService bizExchangeRatesService;

    /**
     * 查询汇率记录列表
     */
    @PreAuthorize("@ss.hasPermi('bluebera:rates:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(BizExchangeRates bizExchangeRates)
    {
        startPage();
        List<BizExchangeRates> list = bizExchangeRatesService.selectBizExchangeRatesList(bizExchangeRates);
        return getDataTable(list);
    }
    /**
     * 查询汇率记录列表
     */
    //@PreAuthorize("@ss.hasPermi('bluebera:rates:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizExchangeRates bizExchangeRates)
    {
        //startPage();
        BizExchangeRates beraRate = bizExchangeRatesService.selectLatestExchangeRate();
        //List<BizExchangeRates> list = bizExchangeRatesService.selectBizExchangeRatesList(bizExchangeRates);
        List<BizExchangeRates> list = new ArrayList<>();
        list.add(beraRate);
        // ethusdt
        beraRate = new BizExchangeRates();
        beraRate.setTokenSymbol("ETH_USDT");
        beraRate.setRateToBluebera(new BigDecimal("0.02"));
        //list.add(beraRate);
        // arbusdt
        beraRate = new BizExchangeRates();
        beraRate.setTokenSymbol("ARB_USDT");
        beraRate.setRateToBluebera(new BigDecimal("0.02"));
        //list.add(beraRate);

        return getDataTable(list);
    }

    /**
     * 导出汇率记录列表
     */
    @PreAuthorize("@ss.hasPermi('bluebera:rates:export')")
    @Log(title = "汇率记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizExchangeRates bizExchangeRates)
    {
        List<BizExchangeRates> list = bizExchangeRatesService.selectBizExchangeRatesList(bizExchangeRates);
        ExcelUtil<BizExchangeRates> util = new ExcelUtil<BizExchangeRates>(BizExchangeRates.class);
        util.exportExcel(response, list, "汇率记录数据");
    }

    /**
     * 获取汇率记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bluebera:rates:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizExchangeRatesService.selectBizExchangeRatesById(id));
    }

    /**
     * 新增汇率记录
     */
    //@PreAuthorize("@ss.hasPermi('bluebera:rates:add')")
    @Log(title = "汇率记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizExchangeRates bizExchangeRates)
    {
        return toAjax(bizExchangeRatesService.insertBizExchangeRates(bizExchangeRates));
    }

    /**
     * 修改汇率记录
     */
    @PreAuthorize("@ss.hasPermi('bluebera:rates:edit')")
    @Log(title = "汇率记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizExchangeRates bizExchangeRates)
    {
        return toAjax(bizExchangeRatesService.updateBizExchangeRates(bizExchangeRates));
    }

    /**
     * 删除汇率记录
     */
    @PreAuthorize("@ss.hasPermi('bluebera:rates:remove')")
    @Log(title = "汇率记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizExchangeRatesService.deleteBizExchangeRatesByIds(ids));
    }
}
